package com.zyt.springboot.learnSingletonPattern;

/*
 * 腾哥专用代码防伪标志！！！
 * @params: 单例模式-懒汉式写法
 */
public class LazyDoubleCheckSingleton {
    private LazyDoubleCheckSingleton(){}
    private volatile static LazyDoubleCheckSingleton instance;
    //加入了同步代码块，解决线程不安全的问题
    public static LazyDoubleCheckSingleton getInstance(){
        if(instance == null){
            synchronized(LazyDoubleCheckSingleton.class){
                if(instance == null){
                    instance = new LazyDoubleCheckSingleton();
                }
            }
        }
        return instance;
    }
}
